<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.example.model.Post" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>编辑博客</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        body {
            background-color: #f5f5f5;
            padding: 20px;
            background-image: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
        }
        
        .page-container {
            max-width: 800px;
            margin: 0 auto;
        }
        
        .page-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
        }
        
        .page-title {
            font-size: 24px;
            font-weight: bold;
            color: #333;
        }
        
        .blog-form {
            background: white;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            padding: 25px;
        }
        
        .form-group {
            margin-bottom: 20px;
        }
        
        .form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: #555;
        }
        
        .form-group input[type="text"],
        .form-group textarea {
            width: 100%;
            padding: 10px 15px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 16px;
            transition: border 0.3s ease;
        }
        
        .form-group input[type="text"]:focus,
        .form-group textarea:focus {
            border-color: #4a90e2;
            outline: none;
            box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.2);
        }
        
        .form-group textarea {
            min-height: 300px;
            resize: vertical;
        }
        
        .form-actions {
            display: flex;
            justify-content: flex-end;
            gap: 15px;
            margin-top: 30px;
        }
        
        .btn {
            padding: 8px 20px;
            border-radius: 4px;
            font-size: 14px;
            cursor: pointer;
            transition: all 0.3s;
        }
        
        .btn-primary {
            background-color: #4a90e2;
            color: white;
            border: none;
        }
        
        .btn-primary:hover {
            background-color: #3a7bc8;
        }
        
        .btn-secondary {
            background-color: white;
            color: #4a90e2;
            border: 1px solid #4a90e2;
            text-decoration: none;
            display: inline-block;
            text-align: center;
        }
        
        .btn-secondary:hover {
            background-color: #f5f9ff;
        }
    </style>
</head>
<body>
<%
    Post post = (Post)request.getAttribute("post");
    boolean isEdit = post != null;
%>

<div class="page-container">
    <div class="page-header">
        <h1 class="page-title"><%= isEdit ? "编辑博客" : "写新博客" %></h1>
    </div>
    
    <div class="blog-form">
        <form method="post" action="${pageContext.request.contextPath}/posts">
            <input type="hidden" name="action" value="<%= isEdit ? "update" : "create" %>">
            <% if (isEdit) { %>
            <input type="hidden" name="id" value="<%= post.getId() %>">
            <% } %>
            
            <div class="form-group">
                <label for="blog-title">标题：</label>
                <input type="text" id="blog-title" name="title" value="<%= isEdit ? post.getTitle() : "" %>" required placeholder="请输入博客标题">
            </div>
            
            <div class="form-group">
                <label for="blog-content">内容：</label>
                <textarea id="blog-content" name="content" required placeholder="请输入博客内容"><%= isEdit ? post.getContent() : "" %></textarea>
            </div>
            
            <div class="form-actions">
                <a href="${pageContext.request.contextPath}/posts" class="btn btn-secondary">返回列表</a>
                <button type="submit" class="btn btn-primary">保存</button>
            </div>
        </form>
    </div>
</div>
</body>
</html> 